package sctu.edu.java.year2016.team07.huangsuixin.day20160610.chapter12_2;

/**
 * Created by Huang Suixin on 2016/6/10.
 */

import sctu.edu.java.year2016.team08.yangying.day20160527.chapter7_1.S;

import java.io.File;
import java.io.IOException;
import java.util.Scanner;

/**
 * 2.编写程序，使用字符输入、输出流读取文件，将一段文字加密后存入文件，然后再读取，
 * 并将加密前与加密后的文件输出。
 */

public class Client {
    public static void main(String[] args) throws IOException {
        String unencryted = "D:\\dev\\Test\\原文件.txt";
        String encrypted = "D:\\dev\\Test\\加密后文件.txt";

        File src = new File(unencryted);
        File des = new File(encrypted);
        try {
            src.createNewFile();
            des.createNewFile();
        } catch (IOException e) {
            System.out.print("已有该文件");
        }

        System.out.println("请输入需要输入的文字：");
        Scanner scan = new Scanner(System.in);
        WriteAndRead altfile = new WriteAndRead();
        String str = scan.nextLine();
        altfile.write(src, str);
        XorEncrypt xor = new XorEncrypt();
        xor.xorEn(src, des);

        System.out.println("加密后的文字：");
        altfile.read(des);
    }
}
